goog.provide('czk.ui.tab.Tab');

goog.require('goog.dom');
goog.require('goog.dom.TagName');

goog.require('czk.ui.ZKComponent');

/**
 * @constructor
 * @extends {czk.ui.ZKComponent}
 */
czk.ui.tab.Tab = function() {
  goog.base(this);
};
goog.inherits(czk.ui.tab.Tab, czk.ui.ZKComponent);

czk.ui.tab.Tab.prototype.btn = null;
czk.ui.tab.Tab.prototype.selected = null;

czk.ui.tab.Tab.prototype.createDom = function() {
  var dh = this.getDomHelper();
  var el = dh.createDom(goog.dom.TagName.DIV);

  this.setElementInternal(el);

  this.setSel(this.selected);

  var el0 = dh.createDom(goog.dom.TagName.DIV, {
    'className': 'inf_btn inf_btn_page'
  });
  goog.dom.insertChildAt(el, el0);

  var el1 = dh.createDom(goog.dom.TagName.DIV, {
    'className': 'btn_left'
  });
  goog.dom.insertChildAt(el0, el1);

  var el2 = dh.createDom(goog.dom.TagName.DIV, {
    'className': 'btn_right'
  });
  goog.dom.insertChildAt(el1, el2);

  this.btn = dh.createDom(goog.dom.TagName.INPUT, {
    'type': 'button',
    'name': this.name,
    'value': this.label,
    'className': 'naviBtn page',
    'onclick': function() {
      return false;
    }
  });
  goog.dom.insertChildAt(el2, this.btn);
};

czk.ui.tab.Tab.prototype.initialize =
    function(name, parameter, portlet, children) {
      goog.base(this, 'initialize', name, parameter, portlet, children);
      if (parameter['selected'])
        this.selected = parameter['selected'];
    };
/** @inheritDoc */
czk.ui.tab.Tab.prototype.enterDocument =
    function() {
      goog.base(this, 'enterDocument');
      this.getHandler().listen(this.btn, goog.events.EventType.CLICK,
          this.select, false, this);
      if (this.selected)
        this.select();
    };

czk.ui.tab.Tab.prototype.select = function() {
  this.getParent().select(this);
};

czk.ui.tab.Tab.prototype.setSel = function(sel) {
  this.selected = sel;
  var c = 'notSel';
  if (sel)
    c = 'sel';
  goog.dom.setProperties(this.getElement(), {
    'className': c
  });
};

czk.ui.tab.Tab.create = function() {
  return new czk.ui.tab.Tab();
};
